package com.guigu.tms.oms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.guigu.tms.commons.order.entity.Order;
import com.guigu.tms.commons.order.entity.vo.Result;
import com.guigu.tms.oms.service.IOrderService;
import com.guigu.tms.oms.service.impl.OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author zwj
 * @since 2022-09-27
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @PostMapping("createOrder")
    public boolean createOrder(@RequestBody Order order){
       return orderService.createOrder(order);
    }

    @PutMapping("cancelOrder/{orderId}")
    public Result cancelOrder(@PathVariable("orderId") String orderId,String cases){
        return orderService.cancelOrder(orderId,cases);
    }

    @PutMapping("updateOrder/{orderId}")
    public Result updateOrder(@PathVariable("orderId") String orderId,@RequestBody Order order){
        return orderService.updateOrder(orderId, order);
    }

    @PostMapping("getOrderPrice")
    public String getOrderPrice(@RequestBody Order order){
        String s = orderService.getOrderPrice(order).toString();
        System.out.println(s);
        return s;
    }

    @GetMapping("getOrdersByMemberId")
    public List<Order> getOrdersByMemberId(String memberId){
       return orderService.getOrdersByMemberId(memberId);
    }

    @GetMapping("getOrdersByMobile")
    public List<Order> getOrdersByMobile(String phone){
        return orderService.getOrdersByMobile(phone);
    }

    @PostMapping("getOrdersByOrder")
    public List<Order> getOrdersByOrder(@RequestBody Order order){
        System.out.println(order);
        QueryWrapper<Order> wrapper = new QueryWrapper<>(order);
        return orderService.list(wrapper);
    }

    @PutMapping("updateOrdeInfo")
    public boolean updateOrderInfo(@RequestBody Order order){
        return orderService.updateById(order);
    }

    @GetMapping("getCourierId")
    public String getCourierId(String position){
        return orderService.getCourierId(position);
    }

    
}
